﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace ResearchId
{
    /// <summary>
    /// Summary description for UserAuthenticate
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class UserAuthenticate : System.Web.Services.WebService
    {

        [WebMethod]
        public bool LoginUser(string Username, string Password, out int IndividualId)
        {
            IndividualId = -1;
            bool Result = Individual.AuthenticateUser(Username, Password);
            if (Result == false)
                return false;
            IndividualId = Individual.GetIndividual(Username).IndividualId;
            return true;
        }
        //[WebMethod]
        //public void AddClaim(int IndividualId, int ClaimId, string Value)
        //{
        //    IndividualClaim.CreateIndividualClaim(IndividualId, (ClaimEnum)ClaimId, Value, "");
        //}
        [WebMethod]
        public void AddClaim(string UserName, int ClaimId, string Value)
        {
            IndividualClaim.CreateIndividualClaim(UserName, (ClaimEnum)ClaimId, Value, "");
        }
        [WebMethod]
        public bool CreateAccount(String Username, string Password)
        {
            try
            {
                Individual.CreateIndividual(Username, Password);
                return true;
            }
            catch {
                return false;
            }

        }
        [WebMethod]
        public int GetUserId(string Username)
        {
            return Individual.GetIndividual(Username).IndividualId;
        }
        [WebMethod]
        public List<IndividualClaimsView> GetClaims(string LoginName, int[] ClaimIds)
        {
            Individual i = Individual.GetIndividual(LoginName);
            return i.GetIndividualClaims(ClaimIds);
        }
        [WebMethod]
        public List<IndividualClaimsView> GetAllClaims(string LoginName)
        {
            Individual i = Individual.GetIndividual(LoginName);
            return i.GetIndividualClaims();
        }
        [WebMethod]
        public List<ClaimView> GetClaimList()
        {
            return Claim.GetClaimView();
        }
    }
}
